package info;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import net.Process;
import org.w3c.dom.Document;
import start.Info;

public class GetUserInfo
{
  public static void getUserInfo(Document doc, boolean getId)
    throws Exception
  {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    Process.info.cookie = xpath.evaluate("//session_id", doc);
    Process.info.userName = xpath.evaluate("//your_data/name", doc);
    Process.info.userLv = xpath.evaluate("//your_data/town_level", doc);
    Process.info.apMax = Integer.parseInt(xpath.evaluate("//your_data/ap/max", doc));
    Process.info.apCurrent = Integer.parseInt(xpath.evaluate("//your_data/ap/current", doc));
    Process.info.bcMax = Integer.parseInt(xpath.evaluate("//your_data/bc/max", doc));
    Process.info.bcCurrent = Integer.parseInt(xpath.evaluate("//your_data/bc/current", doc));
    Process.info.freeApBcPoint = Integer.parseInt(xpath.evaluate("//your_data/free_ap_bc_point", doc));
    if (getId) {
      Process.info.userId = xpath.evaluate("/response/body/login/user_id", doc);
      String wolf = xpath.evaluate("//your_data/owner_card_list/user_card[master_card_id=124][lv=50]/serial_id", doc);

      if ((wolf == null) || (wolf.equals(""))) {
        wolf = xpath.evaluate("//your_data/owner_card_list/user_card[master_card_id=124][lv=60]/serial_id", doc);
      }
      if ((Info.pvpCard.equals("")) && ((wolf == null) || (wolf.equals("")))) {
        Info.isPVP = "0";
      }
      else if (Info.pvpCard.equals("")) {
        Info.pvpCard = wolf + ",empty,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty";
        Info.pvpLr = wolf;
      }

      if ((wolf == null) || (wolf.equals(""))) {
        wolf = xpath.evaluate("//your_data/owner_card_list/user_card[master_card_id=124]/serial_id", doc);
      }
      Info.wolf = wolf + ",empty,empty,empty,empty,empty,empty,empty,empty,empty,empty,empty";
      Info.wolfLr = wolf;
    }
  }
}